﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Collections;
using UMC.Web;
using UMC.WorkFlow.Entities;
using UMC.Data;

namespace UMC.WorkFlow
{

    class TaskDesignGridDialog : UIGridDialog
    {
        public ulong? TaskId { get; set; }
        protected override Hashtable GetHeader()
        {
            var header = new Header("Id", 25);
            header.AddField("Name", "流程名");
            header.AddField("Status", "版本");
            this.IsAsyncData = true;
            return header.GetHeader();

        }
        protected override Hashtable GetData(IDictionary paramsKey)
        {

            var form =  DataFactory.Instance().TaskForm(TaskId.Value);


            var data = new System.Data.DataTable();
            data.Columns.Add("Id");
            data.Columns.Add("Name");
            data.Columns.Add("Status");

            Utility.Each(DataFactory.Instance().TaskDesigns(TaskId.Value), dr =>
            {
                data.Rows.Add(dr.Id, String.Format("{0} v{1}.{2}", form.Caption, ((dr.Version ?? 0) / 10) + 1, (dr.Version ?? 0) % 10), dr.Id == form.DesignId ? "运行" : "");
            });


            var hash = new Hashtable();
            hash["data"] = data;
            return hash;
        }
    }

}